<html>
	<head>
		<link rel = "stylesheet" href = "style.css">
		<script src="jquery-1.11.0.js"></script>
		<script>
	
			function showSchedulePopUp(obj){
				var x=obj.offsetLeft;
				var y=obj.offsetTop+20;
				$("#divSchedule").offset({top:y,left:y});
				$("#divSchedule").fadeIn( "slow");
			}
			
			function hideSchedulePopUp(){
				$("#divSchedule").fadeOut( "slow");
			}
		</script>

	</head>
	<body>
		<table>
			<tr>
				<td colspan="2" id="pageheader">
					HEALTH INFORMATION SYSTEMS
				</td>
			</tr>
			<tr>
				<td id="mainnav">
					<div class="menuitem"><a href = "community_lists.php">Community</a></div>
					<div class="menuitem">Subdistricts</div>
					<div class="menuitem"><span class="menuitem" ><a href = "community_add.php" target="_blank">Add to the community table</a></span></div>
					
					<div class="menuitem"></div>
					<div class="menuitem"></div>
					<div class="menuitem"></div>
				
				</td>
				<td id="content">
			
					<div id="divPageMenu">
						<span class="menuitem" >User accounts</span>
						<input type="text" id="txtSearch">
						<span class="menuitem">search</span>		
					</div>
					<!-- <div id="divStatus" class="status">
						Welcome to the Health Information System -->
					
					<div id="divContent">
						

		<table class="reportTable" width="100%">
			<tr class="header" >
			<td>community Add</td>
		</tr>

		

<?php

	// function add(){
	// 	//alert up to say are you sure you want to save
	// 	//yes -> save in databae
	// 	//no -> redirect to  homepage
	// 	//use onclick for this
	// }

	$community_id = null;
	//if(isset($_REQUEST["community_id"])){
	//$community_id = $_REQUEST["community_id"];
	//}
		
	$latitude = 0;
	if(isset($_REQUEST["latitude"])){
	$latitude = $_REQUEST["latitude"];
	}
			$longitude = 0;
	if(isset($_REQUEST["longitude"])){
	$longitude = $_REQUEST["longitude"];
	}
	
	
	$population = 0;
	if(isset($_REQUEST["population"])){
	$population = $_REQUEST["population"];
	}
	
	$household = 0;
	if(isset($_REQUEST["household"])){
	$household= $_REQUEST["household"];
	}
	
		$community_name = "";
	if(isset($_REQUEST["community_name"])){
	$community_name = $_REQUEST["community_name"];
	}
	
/*	$subdistrict_id = 0;
	if(isset($_REQUEST["subdistrict_id"])){
	$subdistrict_id = $_REQUEST["subdistrict_id"];
	} */
	
	$subdistrict_id = 0;
	if(isset($_REQUEST["subdistrict_id"])){
	$subdistrict_id = $_REQUEST["subdistrict_id"];
	}
	
	if($subdistrict_id == 0){
	$query = mysql_query("select*from community");
	}else{
	$query =mysql_query("select * from community where subdistrict_id = $subdistrict_id");
	}
	
	
		include("community.php");
	$obj = new community();
	if(!$obj -> add_community($community_id,  $latitude, $longitude,
				$population, $household, $community_name, $subdistrict_id)){
		echo"error";
		echo mysql_error($obj->link);
		exit();
	}
	
	//$row = $obj -> fetch();
	//print_r($row);
	//mysql_query($row,$link);
	
	
	

	
	
	
?>
<form  action="community_add.php" method = "GET" onsubmit = "validate()">
			<table class = "tableForm">

		<tr>
			<td class = "label"> Community Name: </td>
			<td class = "field"><input type = "text"  name = "community_name"></td>
		</tr>
		<tr>
			<td class = "label"> Longitude: </td>
			<td class = "field"><input type = "text"  name = "longitude"></td>
		</tr>
		<tr>
			<td class = "label"> Latitude: </td>
			<td class = "field"><input type = "text"  name = "latitude"></td>
		</tr>
		<tr>
			<td class = "label"> Population: </td>
			<td class = "field"><input type = "text"  name = "population"></td>
		</tr>
		<tr>
			<td class = "label"> Household: </td>
			<td class = "field"><input type = "text"  name = "household"></td>
		</tr>	
				
		<tr>
			<td class = "label"> Subdistrict: </td>
				<td><select name="subdistrict_id">
				<option value = "0" > All	</option>
				<option value = "1" > Aburi </option>
				<option value = "2"> Pokrum </option></td>	
	</select>
		</tr>
		<tr>
	<td><input type = "submit" name = "submit" value ="Add"></td>
</tr>
</td>
	</form>
			</table>
			<div id="divSchedule" class="popupMenu" onclick="hideSchedulePopUp()">
			<div> at birth</div>
			<div> 6 weeks</div>
			<div> 10 weeks</div>
		</div>
						
					<!-- </div> -->

			<!-- </tr> -->
			</table>
				
	</body>
</html>	
	